package com.xidian.zhiancloud.controller.exam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.exam.TrainContent;
import com.xidian.zhiancloud.service.exam.ITrainContentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;


/**
 * 培训内容Controller
 * 
 * @author zhouweitao
 * @date 2021-03-16
 */
@RestController
@RequestMapping("/trainContents")
public class TTrainContentController 
{
    @Autowired
    private ITrainContentService trainContentService;

    /**
     * 查询培训内容列表
     */
    @GetMapping("/list")
    public ResultDTO list( TrainContent trainContent)
    {
        Page<TrainContent> pagedata = trainContentService.selectTrainContentList(trainContent);
        Map<String, Object> data = new HashMap<String, Object>();
		data.put("datalist", pagedata);
		data.put("PageNum", pagedata.getPageNum()+1);
		data.put("PageSize", pagedata.getPageSize());
		data.put("PageTotal", pagedata.getPages());
		data.put("total", pagedata.getTotal());
		return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
    }



    /**
     * 获取培训内容详细信息
     */
    @GetMapping(value = "/{id}")
    public ResultDTO getInfo(@PathVariable("id") Long id)
    {
        return ResultDTO.successOf(trainContentService.selectTrainContentById(id), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 新增培训内容
     */
    @PostMapping
    public ResultDTO add(@RequestBody TrainContent trainContent)
    {
        trainContentService.insertTrainContent(trainContent);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 修改培训内容
     */
    @PutMapping
    public ResultDTO edit(@RequestBody TrainContent trainContent)
    {
        trainContentService.updateTrainContent(trainContent);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 删除培训内容
     */
	@DeleteMapping("/{ids}")
    public ResultDTO remove(@PathVariable Long[] ids)
    {
        trainContentService.deleteTrainContentByIds(ids);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
}
